package com.dit.action;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.dit.core.User;
import com.dit.entity.SystemUser;
import com.dit.service.SystemUserService;
import com.opensymphony.xwork2.ActionSupport;

public class SignInAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private User user;
	private List<User> userList =new ArrayList<User>(0);
	
	@Autowired private SystemUserService systemUserService;

	public List<User> getUserList() {
		return userList;
	}

	public void setUserList(List<User> userList) {
		this.userList = userList;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String home() {
		return SUCCESS;
	}

	public String signIn(){
		userList.add(new User("admin", "admin", "male"));
		userList.add(new User("user1", "abc", "male"));
		userList.add(new User("user2", "abc", "female"));
		
		
		SystemUser su=systemUserService.findByID("U001");
		System.out.println(su.getUsername());
		return SUCCESS;
	}

	public String signUp(){
		return SUCCESS;
	}

	public String validateUser() {
		if(user.getUserName().equals("admin") && user.getUserPassword().equals("admin")){
			return SUCCESS;
		}
		else{
			addFieldError("user.userName", "Invalid Username");
			addFieldError("user.userPassword", "Invalid Password");
			user.setUserName(user.getUserName());
			return ERROR;
		}
	}

	public String registerUser(){
		return SUCCESS;
	}





}
